<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/8/24 0024
  Time: 10:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path = request.getContextPath();%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script src="<%=path%>/static/js/jquery-3.5.1.min.js"></script>

<table class="result-tab" width="100%">
    <tr>
        <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
        <th>ID</th>
        <th>民族</th>
        <th>添加时间</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${requestScope.nations}" var="nation">
        <tr>
            <td class="tc">
                <input name="id[]" id="choose" value="${nation.id}" type="checkbox"></td>
            <td>
                    ${nation.id}
                    <%--<input name="ids[]" value="59" type="hidden">
                    <input class="common-input sort-input" name="ord[]" value="0" type="text">--%>
            </td>
            <td>${nation.nationName}</td>
            <td><fmt:formatDate value="${nation.createdTime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
            <td>
                <a class="link-del" href="#" data-id="${nation.id}">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>
<div class="list-page">
    ${requestScope.pageInfo.pages}页
    <a href="#" data-pagenum="1">首页 </a>
    <c:if test="${requestScope.pageInfo.pageNum gt 1}">
        <a href="#" data-pagenum="${requestScope.pageInfo.pageNum-1}">上一页</a>
    </c:if>

    <c:forEach begin="1" end="${requestScope.pageInfo.pages}" var="i">

        <a href="#" data-pagenum="${i}"
                <c:if test="${i eq requestScope.pageInfo.pageNum}"> class="current" </c:if>>${i}</a>
    </c:forEach>

    <c:if test="${requestScope.pageInfo.pageNum lt requestScope.pageInfo.pages}">
        <a href="#" data-pagenum="${requestScope.pageInfo.pageNum+1}">下一页</a>
    </c:if>
    <a href="#" data-pagenum="${requestScope.pageInfo.pages}">尾页 </a>
    ${requestScope.pageInfo.pageNum}/${requestScope.pageInfo.pages}页
</div>
<script>
    var path = "${pageContext.request.contextPath}";
    $(function () {
        $(".link-del").click(function () {
            var id = $(this).data("id");
            var ansswer = confirm("确定删除吗？");
            if(ansswer){
                $.get(path+"/manage/nations/delete",
                    {id:id},
                    function () {
                        $(this).parent().parent().remove();
                    }.bind(this));
            }
            else {
                return false;
            }
        });
    });
</script>
<script>
    $(function () {
        $("#insert").click(function () {
            $("#hide").css("display","block");
        });
    });
    $(function () {
        $("#but").click(function () {
            $("#hide").css("display","none");
        });
    });
    $(function () {
        $("#button").click(function () {
            var title = $("#setUp").val();
            if (title==""){
                return;
            }
            $.get("<%=path%>/manage/degree/insert",{title:title},function (data) {
                $("#hide").css("display","none");
                if (data=="ok"){
                    location.reload();
                }
            });
        });
    });
    $(function () {
        $(".allChoose").click(function () {
            $(":checkbox[id='choose']").prop("checked",$(this).prop("checked"));
        });

    });
    $(function () {
        batchDel();
    });
    function batchDel() {
        $("#batchDel").click(function () {
            var idArr = new Array();
            $(":checked[id='choose']").each(function () {
                idArr.push($(this).val());
            });
            if (idArr.length>0){
                $.get("<%=path%>/manage/degree/batchDel",{idArr:idArr.toString()},function () {
                    for (var i=0;i<idArr.length;i++){
                        if ($(":checked[id='choose']").val()==idArr[i]){
                            $(":checked[id='choose']").parent().parent().remove();
                        }
                    }
                });
            }
        });
    }
</script>
<script>
    $(function () {
    var id = "";
    $(".link-update").click(function () {
    var name = $(this).parent().prev().prev().html();
    $("#setResume").val(name);
    id = $(this).attr("id");
    $("#hideing").css("display","block");
    });
    $("#butt").click(function () {
    $("#hideing").css("display","none");
    });
    $("#buttons").click(function () {
    var title = $("#setResume").val();
    if (title==""){
    return;
    }
    $.get("<%=path%>/manage/nations/update",{title:title,id:id},function () {
    $("#hideing").css("display","none");
    location.reload();
    });
    });
    });
</script>